package com.jumei.flume.parser;

import com.google.common.base.Preconditions;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Context {
    //常量
    public final static String MSG = "param";

    private Map<String, Object> paramMap = new HashMap<String, Object>();

    public void setParameter(List<String> messages) {
        paramMap.put(MSG, messages);
    }
    
    public List<String> getParameter() {
        if (CollectionUtils.isEmpty(paramMap) || paramMap.get(MSG) == null) {
            return null;
        }

        return (List<String>) paramMap.get(MSG);
    }

    public void setParameter(String key, Object o) {
        Preconditions.checkNotNull(key != null, "key should not be null!");
        paramMap.put(key, o);
    }
    
    public <T> T getParameter(String key) {
        if (CollectionUtils.isEmpty(paramMap)) {
            return null;
        }

        return (T) paramMap.get(key);
    }
    
    public void release() {
        paramMap.clear();
    }
}

